﻿namespace JunFan.Mapping
{
    using System;
    using AutoMapper;
    using Domain;
    using ViewModels;
    using DTO = Repositories.Dtos;

    internal class MappingProfile : Profile
    {
            protected override void Configure()
            {
                base.Configure();

                CreateMaps();
            }

        private static void CreateMaps()
        {
            // Convert all DateTime with default value into a DateTime? null
            Mapper.CreateMap<DateTime, DateTime?>().ConvertUsing<DateTimeNullableConverter>();

            Mapper.CreateMap<DTO.Item, Item>()
                  .ForMember(to => to.InternalId, option => option.MapFrom(from => @from.Id))
                  .ForMember(to => to.Id, option => option.MapFrom(from => @from.ExternalId));


            Mapper.CreateMap<Item, DTO.Item>()
                  .ForMember(to => to.ExternalId, option => option.MapFrom(from => @from.Id))
                  .ForMember(to => to.Id, option => option.MapFrom(from => @from.InternalId));

            Mapper.CreateMap<Item, ItemView>();
            Mapper.CreateMap<ItemView, Item>();
        }
    }
}